<?php

declare(strict_types=1);

namespace Modules\User\Models;

use Catch\Base\CatchModel as Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Permissions\Models\Traits\DataRange;

/**
 * 管理员行为日志模型
 * 
 * @property int $id
 * @property string $action 操作行为
 * @property string $operate_ip IP地址
 * @property int $creator_id 操作者ID
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 * @property string $module 模块
 * @property string $business 业务
 * @property string $operation 操作详情
 * @property string $related_id 关联ID
 * @property string $remark 备注
 */
class LogBehavior extends Model
{
    use DataRange;

    protected $table = 'log_behavior';
    public $timestamps = true;

    /**
     * 批量赋值字段
     */
    protected $fillable = ['action', 'operate_ip', 'creator_id', 'created_at', 'updated_at', 'module', 'business', 'operation', 'related_id', 'remark'];

    /**
     * CatchAdmin表格显示字段
     */
    protected array $fields = [
        'id', 'action', 'operate_ip', 'creator_id', 'created_at', 'module', 'business', 'operation', 'related_id', 'remark'
    ];

    /**
     * CatchAdmin表单字段
     */
    protected array $form = [
        'action', 'operate_ip', 'module', 'business', 'operation', 'related_id', 'remark'
    ];

    /**
     * 类型转换
     */
    protected $casts = [
        'creator_id' => 'integer',
        'created_at' => 'integer',
        'updated_at' => 'integer',
        'deleted_at' => 'integer',
    ];

    /**
     * CatchAdmin列表查询字段
     */
//    public array $searchable = [
//        'module' => '=',
//        'business' => '=',
//        'action' => 'like',
//        'created_at' => 'between'
//    ];

    /**
     * 关联操作者
     */
    public function creator(): BelongsTo
    {
        return $this->belongsTo(\Modules\User\Models\User::class, 'creator_id');
    }
}